/**
 * @Date 2023-02-23 16:22:27
 * @Remark
 */

// lib
// config
// script & methods & public
import toast from "components/toast";
// store
import { state } from "./state";
// service
import {
  updateUserPwdService,
  logoutService,
  letUserInfoUpdateService,
} from "biz/Auth/service";

import { ReqUpdateInfo } from "biz/Auth/api";
// interface
// 其它

export async function letUserPwd(oldPwd: string, newPwd: string) {
  // 开始前
  state.pwdLoading = true;
  // 调用服务
  const result = await updateUserPwdService(oldPwd, newPwd);
  // 结束后
  state.pwdLoading = false;
  // 成功
  if (result.payload) {
    state.pwdModal = false;
    toast.success("密码修改成功,3秒后退出系统");
    setTimeout(() => {
      logoutService();
    }, 3000);
  }
}

export async function letUserInfoUpdate(params: ReqUpdateInfo) {
  // 调用服务
  state.infoLoading = true;
  const result = await letUserInfoUpdateService(params);
  state.infoLoading = false;
  // 成功
  if (result.payload) {
    state.infoModal = false;
    toast.success("信息修改成功,3秒后退出系统");
    setTimeout(() => {
      logoutService();
    }, 3000);
  }
}

export async function init() {
  // 加载动态字典
  // getDictService();
  // 加载静态字典
  state.ready = false;
  // await getStaticDictService();
  state.ready = true;
  // 加载地区
  // getAntdCascaderArea();
}
